package mathFrame

import scalafx.scene.layout.StackPane
import scalafx.scene.shape._

class Plotter2D() extends StackPane {
  var func: UserFunction1P = NoValue
  var minX = -3.14
  var maxX = 3.14
  var step = 0.01
  var escalaX = 100
  var escalaY = -100
  var transposeX = 3.14
  var transposeY = -3.14
  
  def function: Value = func
  def function_=(v: UserFunction1P):Unit = {
    func = v
  }
  
  def regenerate() {
    getChildren.clear
    if (func != NoValue) {
      var vx = minX
      val path = new Path
      val start = new MoveTo {
        x = (vx + transposeX) * escalaX
        y = (func.value(vx) + transposeY) * escalaY
      }
      path.getElements add start
      while (vx < maxX) {
        vx += step
        val line = new LineTo {
          x = (vx + transposeX) * escalaX
          y = (func.value(vx) + transposeY) * escalaY
        }
        path.getElements add line
      }
      getChildren add path
      println("Done")
    }
  }
}
